package com.sifeng.test;

import com.sifeng.enums.FileTypeEnum;
import com.sifeng.utils.MyUtils;
import jxl.write.biff.File;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by yang_gsh on 2018/9/11.
 * 获取复评材料的单元数量
 */
public class ExportFunctionPointUnitQuantity {
	private static String path = "E:\\hisun\\开发三部\\功能点评估表\\201811\\11月开发复评材料-杨贵生";

	public static int getPointUnitQuantity(String excelPath) throws IOException, InvalidFormatException {
		InputStream iStream=new FileInputStream(excelPath);
		XSSFWorkbook wb = new XSSFWorkbook(iStream);
		XSSFSheet sheet = wb.getSheetAt(0);
		if (sheet == null) {
			return -1;
		}
		boolean whileFlg = true;
		int index = 6;
		int pointUnitQuantity = 0;
		while (whileFlg) {
			XSSFRow row = sheet.getRow(index);
			XSSFCell cell = row.getCell(8);
			cell.setCellType(Cell.CELL_TYPE_STRING);
			String tmp = cell.getStringCellValue();
			if (tmp == null || "".equals(tmp.trim())) {
				whileFlg = false;
			} else {
				pointUnitQuantity = pointUnitQuantity + Integer.parseInt(tmp.trim());
			}
			index++;
		}

		return pointUnitQuantity;
	}

	public static void main(String[] args) throws IOException, InvalidFormatException {
		List<String> list = MyUtils.readDirectory(path, FileTypeEnum.DIRECTORY);
		for (String directoryName : list) {
			List<String> fileList = MyUtils.readDirectory(path + "\\" + directoryName,FileTypeEnum.FILE);
			for (String fileListName : fileList) {
				if (fileListName.contains("原子功能点评估表")) {
					int num = ExportFunctionPointUnitQuantity.getPointUnitQuantity(path + "\\" + directoryName + "\\" +fileListName);
					System.out.println(fileListName + ":" + num);

				}
			}
		}

	}
}
